using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GameAOT;
using System;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_StoryOptionItem : UIBaseNode
    {

        #region Template Generate,don't modify
        protected partial class UIB_UINStoryOptionItem
        {
            #region ObjectBinding Generate
            public IQIGame.Onigao.Framework.ExButton btn_option { protected set; get; }
            public IQIGame.Onigao.Framework.ExText btn_text { protected set; get; }
            protected virtual void InitBinding(ObjectBinding __binding)
            {
                var __tbv0 = __binding.GetVariableByName("btn_option");
                this.btn_option = __tbv0.GetValue<IQIGame.Onigao.Framework.ExButton>();
                var __tbv1 = __binding.GetVariableByName("btn_text");
                this.btn_text = __tbv1.GetValue<IQIGame.Onigao.Framework.ExText>();
            }

            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        /// <summary>
        /// 可以自定义修改的
        /// </summary>
        protected partial class UIB_UINStoryOptionItem
        {
            public virtual void StartBinding(GameObject __go)
            {
                var binding = __go.GetComponent<ObjectBinding>();
                if (binding != null)
                {
                    this.InitBinding(binding);
                }
            }
        }
        protected UIB_UINStoryOptionItem ui { get; set; }

        private int index;
        private Action<int> clickEvent;

        protected override void BeforeInit()
        {
            ui = new UIB_UINStoryOptionItem();
            ui.StartBinding(gameObject);
        }

        protected override void OnInit()
        {
            this.ui.btn_option.AddClickEvent(OnBtnOptionClicked);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        public void InitOptionItem(int index, string content, Action<int> clickEvent)
        {
            this.index = index;
            this.clickEvent = clickEvent;
            this.ui.btn_text.text = content;
        }

        private void OnBtnOptionClicked()
        {
            clickEvent?.Invoke(this.index);
        }

        protected override void OnDispose()
        {

        }
    }
}